package com.bblocks.enums;

import com.bblocks.config.SwaggerDisplayEnum;
import com.bblocks.exception.ServiceException;
import lombok.Getter;
import lombok.NonNull;

/**
 * 目前OAuth2支持：密码、短信模式
 * 后续可以继承自己的登录方式如微信登录登
 */
@Getter
@SwaggerDisplayEnum(index = "type", name = "name")
public enum LoginTypeEnum {
	Psw(1, "password"),
	Sms(2, "sms"),


	;

	private Integer type;
	private String name;

	LoginTypeEnum(Integer type, String name) {
		this.type = type;
		this.name = name;
	}


	@Override
	public String toString() {
		return String.valueOf(type) + ":" + name;
	}

	private static LoginTypeEnum[] all =  LoginTypeEnum.values();
	public static LoginTypeEnum getLoginTypeEnum(@NonNull Integer loginType) {
		for (LoginTypeEnum c : all) {
			if (c.getType().equals(loginType) ) {
				return c;
			}
		}
		throw new ServiceException("无此登录类型："+loginType);
	}

	public static LoginTypeEnum getLoginTypeEnum(@NonNull String loginName) {
		for (LoginTypeEnum c : all) {
			if (c.getName().equals(loginName) ) {
				return c;
			}
		}
		throw new ServiceException("无此登录名称："+loginName);
	}
}
